// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Author: wsfuyibing <682805@qq.com>
// Date: 2024-11-13

package conf

const (
    DefaultElasticLoggerAddresses = "http://127.0.0.1:9200"
    DefaultElasticLoggerIndex     = "log-2006.01.02"
    DefaultElasticLoggerIndexType = "_doc"
    DefaultElasticLoggerTimeout   = 5
)

// ElasticAdapterConfig
// Elasticsearch 配置.
type ElasticAdapterConfig struct {
    // Addresses
    // Elasticsearch 地址.
    Addresses []string `yaml:"addresses"`

    // Index
    // 索引名称.
    Index string `yaml:"index"`

    // IndexType
    // 索引类型.
    IndexType string `yaml:"index-type"`

    // Timeout
    // 超时时长.
    Timeout int `yaml:"timeout"`

    Username string `yaml:"username"`
    Password string `yaml:"password"`
}

// +---------------------------------------------------------------------------+
// | Access methods                                                            |
// +---------------------------------------------------------------------------+

func (o *ElasticAdapterConfig) init() {
    if len(o.Addresses) == 0 {
        o.Addresses = []string{DefaultElasticLoggerAddresses}
    }
    if o.Index == "" {
        o.Index = DefaultElasticLoggerIndex
    }
    if o.IndexType == "" {
        o.IndexType = DefaultElasticLoggerIndexType
    }
    if o.Timeout == 0 {
        o.Timeout = DefaultElasticLoggerTimeout
    }
}
